//## 장비휴지 정보 저장 ####################
function fnSave()
{
	if (!$("#equipCd").val())
	{
		alert("장비를 선택해 주세요!");
		$("#equipCd").focus();
		return;
	}
	if (!$("#breakDt").val())
	{
		alert("날짜를 바르게 입력해 주세요!");
		$("#breakDt").focus();
		return;
	}
	if (!$("#breakTm").val())
	{
		alert("휴지시간을 바르게 입력해 주세요!");
		$("#breakTm").focus();
		return;
	}
	if (!$("#fullLotNo").val())
	{
		alert("Lot No를 선택해 주세요!");
		$("#fullLotNo").focus();
		return;
	}
	var param  = "equipCd="+$("#equipCd").val();
		param += "&remark="+encodeURIComponent($("#remark").val());
		param += "&breakDt="+$("#breakDt").val();
		param += "&breakTm="+$("#breakTm").val();
		param += "&fullLotNo="+$("#fullLotNo").val();
		param += "&flag="+$("#flag").val();
		param += "&seq="+$("#seq").val();

	$.ajax({
		url: '/action/equipBreak/save.asp',
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			fnSessionCheck($(xml).find("MSG").text());
			if ($(xml).find("MSG").text() == "Save OK!")
			{
				alert("Save OK!");
				frmEquip.reset();
				grid01List();
			}
			else alert($(xml).find("MSG").text());
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

//## 장비휴지 정보 그리드 표시 ####################

var G_grid01Rslt = "" //XML Data를 받을 전역변수 선언

function grid01List()
{
	clstTable("Grid01");
	$("#tr01Result").show();
	setNullRow("loadSpan","1");
	var valUrl = "/action/equipBreak/list.asp";
	var param = "findLotNo="+encodeURIComponent($("#findLotNo").val());
		param += "&findEquipCd="+encodeURIComponent($("#findEquipCd").val());
		param += "&findStartDt="+encodeURIComponent($("#findStartDt").val());
		param += "&findEndDt="+encodeURIComponent($("#findEndDt").val());
		if ($("#listMode").is(":checked")) param += "&listMode=Y";

	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());

			G_grid01Rslt = xml;
			setGrid01(1);
		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

function setGrid01(curPage)
{
	clstTable("Grid01");

	$("#tr01Result").css("display","none");
	$("#loadSpan1").html("");
	var nodeCnt = $(G_grid01Rslt).find("Equipment").find("BreakList").length;

	if(nodeCnt == 0)
	{
		$("#tr01Result").css("display","");
		$("#loadSpan1").html("검색된 자료가 없습니다.");
		$("#grid01Cnt").html("0");
		return;
	}
	var listNum = 50;
	var totalCount = nodeCnt;
	$("#grid01Cnt").html(totalCount);
	if (curPage == "") curPage = 1;
	var totalPage = Math.ceil(nodeCnt/listNum);
	var restArticle = (nodeCnt%listNum);
	startNo = (parseInt(curPage)-1) * listNum;	
	var endNo = startNo + listNum;
	
	nodeCnt = nodeCnt - ((curPage-1)*listNum);
	if (totalPage == curPage)
	{
		if (restArticle == 0) var endNo = startNo + listNum;
		else var endNo = startNo + restArticle;
	}

	var pages = fnPaging("Grid01", curPage, totalPage);

	$("#pageDiv01").html(pages);
	
	var grid01Array = new Array();
	var chkCnt = 0;
	for(var j=startNo; j<endNo; j++)
	{
		var seq			= $(G_grid01Rslt).find("Equipment").find("BreakList").eq(j).find("seq").text();
		var itemNm	= $(G_grid01Rslt).find("Equipment").find("BreakList").eq(j).find("itemNm").text();
		var breakDt	= $(G_grid01Rslt).find("Equipment").find("BreakList").eq(j).find("breakDt").text();
		var breakTm	= $(G_grid01Rslt).find("Equipment").find("BreakList").eq(j).find("breakTm").text();
		var fullLotNo	= $(G_grid01Rslt).find("Equipment").find("BreakList").eq(j).find("fullLotNo").text();		
		var flag			= $(G_grid01Rslt).find("Equipment").find("BreakList").eq(j).find("flag").text();

		ji = j+1;
		
		var showFlag = "";
		if(flag == "Y") showFlag = "유효";
		else showFlag = "삭제";
		
		if (flag == "N") var bgColor = "#F2F2F2";
		else var bgColor = "#FFFFFF";

		grid01Array[0] = ji;
		grid01Array[1] = itemNm;
		grid01Array[2] = breakDt;
		grid01Array[3] = breakTm;
		grid01Array[4] = fullLotNo;
		grid01Array[5] = showFlag;

		var boldLine = ""
		if (ji%10 == 0 && ji != 1) boldLine = "Y"
		
		mkTable2("Grid01", grid01Array, bgColor, ",,,,,,", "fnSetEquipBreak('"+seq+"')", boldLine);
	}
}


//## 장비휴지 상세정보 표시 ####################
function fnSetEquipBreak(seq)
{
	var valUrl = "/action/equipBreak/view.asp";
	var param = "seq="+seq;
	if (seq == 0)
	{
		alert("합산모드에서는 상세정보를 표시할 수 없습니다.\n합산모드를 해제후 선택해 주세요");
		$("#listMode").focus();
		return;
	}
	if (xMode=="debug") window.open(valUrl+'?xMode=debug&'+param);

	$.ajax({
		url: valUrl,
		type: 'POST',
		dataType: 'xml',
		data: param,
		success: function(xml){
			
			//## 로그인 체크
			fnSessionCheck($(xml).find("MSG").text());

			$("#seq").val($(xml).find("seq").text());
			$("#equipCd").val($(xml).find("equipCd").text());
			$("#breakDt").val($(xml).find("breakDt").text());
			$("#breakTm").val($(xml).find("breakTm").text());
			$("#fullLotNo").val($(xml).find("fullLotNo").text());
			$("#remark").val($(xml).find("remark").text());
			$("#flag").val($(xml).find("flag").text());
			if ($(xml).find("updateDt").text())
			{
				$("#accessInfo").val("최종수정 : "+$(xml).find("updateDt").text());
			}
			else
			{
				$("#accessInfo").val("최종수정 : "+$(xml).find("issueDt").text());
			}

		},
		error: function(xml){
			alert('Error!!');
			alert(xml.responseText);
		}
	});
}

//## 검색 Reset 기능
function fnSearchReset()
{
	$("#findCompany").val("");
	$("#findMajor").val("");
}